﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using GoShopping.Model;
using GoShopping.BLL;

public partial class ProductListShow : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //"select * from dbo.ProductType where ID in (select ProductTypeID  from dbo.Product where Brand='samsung'"
            InitialPage();
        }
        ProductTypeNavigator1.PrdtTypeList = new GoShopping.BLL.ProductTypeBean().GetAllProductTypeList();
    }
    private const string prdtConfig = @"~/Config/PrdtConfig.xml";

    void InitialPage()
    {
        GetResultList();

        dlBrandList.DataSource = XMLManipulation.GetConfig(Server.MapPath(prdtConfig), "//Index/Brand");
        dlBrandList.DataBind();

        dlFriendlyLink.DataSource = XMLManipulation.GetConfig(Server.MapPath(prdtConfig), "//Index/FriendlyLink");
        dlFriendlyLink.DataBind();
    }

    private void GetResultList()
    {
        if (Request.QueryString["Product"] != null)
        {
            string filterString = " AND IsShowOnSale='true' AND Name LIKE '%" + Request.QueryString["Product"] + "%'";
            BindListView(filterString);
        }
        else if (Request.QueryString["Brand"] != null)
        {
            string filterString = " AND IsShowOnSale='true' AND Brand LIKE '%" + Request.QueryString["Brand"] + "%'";
            BindListView(filterString);
        }
        else if (Request.QueryString["ProductType"] != null)
        {
            string filterString = " AND IsShowOnSale='true' AND ProductTypeID IN (SELECT ID FROM ProductType WHERE TypeName LIKE '%" + Request.QueryString["ProductType"] + "%')";
            BindListView(filterString);
        }
        else if (Request.QueryString["Supplyer"] != null)
        {
            string filterString = " AND IsShowOnSale='true' AND SupplyerID IN (SELECT ID FROM PrdctSupplyer WHERE Name LIKE '%" + Request.QueryString["Supplyer"] + "%')";
            BindListView(filterString);
        }
        else
        {
 
        }
    }

    private void BindListView(string filterString)
    {
        Cache["filter"] = filterString;
        ProductBean pb = new ProductBean();
        cplPrdts.LVPrdts.DataSource = pb.GetProductList(filterString);
        cplPrdts.LVPrdts.DataBind();
    }
}
